package com.jz.netthings.application.providerCollection.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jz.netthings.application.providerAllot.bean.ProviderAllot;
import com.jz.netthings.application.providerAllot.bean.QueryProviderAllot;
import com.jz.netthings.application.providerAllot.service.ProviderAllotService;
import com.jz.netthings.application.providerCollection.bean.ProviderCollection;
import com.jz.netthings.application.providerCollection.bean.QueryProviderCollection;
import com.jz.netthings.application.providerCollection.service.ProviderCollectionService;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.security.utils.Token;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-03-14
 */
@RestController
@RequestMapping("/adscm/application/providerCollection")
public class ProviderCollectionController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    ProviderCollectionService providerCollectionService;

    /**
     * 查询未处理采浆记录
     * @param queryProviderCollection
     * @param request
     * @return
     * @throws AdscmSystemException
     * @throws IOException
     */
    @RequestMapping("/selectNoDealProviderCollection")
    public SimpleCoreResponse selectNoDealProviderCollection(/*@RequestBody */QueryProviderCollection queryProviderCollection, HttpServletRequest request) throws AdscmSystemException, IOException {
        Page<ProviderCollection> page =new Page<>(queryProviderCollection.getCurrentPage(),queryProviderCollection.getPageSize());
        Page<ProviderCollection>  providerCollections = providerCollectionService.selectNoDealProviderCollection(page ,queryProviderCollection);
        return new SimpleCoreResponse("200","查询成功" ,providerCollections);
    }

    /**
     * 修改未处理采浆记录
     * @param providerCollection
     * @param request
     * @return
     * @throws AdscmSystemException
     * @throws IOException
     */
    @RequestMapping("/updateNoDealProviderCollection")
    public SimpleCoreResponse updateNoDealProviderCollection(@RequestBody ProviderCollection providerCollection, HttpServletRequest request) throws AdscmSystemException, IOException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
          Boolean result = providerCollectionService.updateNoDealProviderCollection(providerCollection,token);
        return new SimpleCoreResponse("200","查询成功" ,result);
    }
    @RequestMapping("/selectProviderCollection")
    public SimpleCoreResponse selectProviderCollection(@RequestBody QueryProviderCollection queryProviderCollection, HttpServletRequest request) throws AdscmSystemException, IOException {
        Page<ProviderCollection> page =new Page<>(queryProviderCollection.getCurrentPage(),queryProviderCollection.getPageSize());
        Page<ProviderCollection>  providerCollections = providerCollectionService.selectProviderCollection(page ,queryProviderCollection);
        return new SimpleCoreResponse("200","查询成功" ,providerCollections);
    }
    @RequestMapping("/selectById/{id}")
    public SimpleCoreResponse selectById(@PathVariable String id, HttpServletRequest request) throws AdscmSystemException, IOException {
        ProviderCollection        providerCollections = providerCollectionService.selectProviderCollectionById(id);
        return new SimpleCoreResponse("200","查询成功" ,providerCollections);
    }


    /**
     * 查询采浆打印数据
     * @param startDate 采浆开始时间
     * @param endDate 采浆结束时间
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/selectPrintList")
    public SimpleCoreResponse selectPrintList(String startDate,String endDate) throws AdscmSystemException{

        return new SimpleCoreResponse("200","查询成功" ,providerCollectionService.selectPrintList(startDate,endDate));
    }


}

